package com.atguigu.springcloud.controller;

import java.util.List;

import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.atguigu.springcloud.entities.Dept;
import org.springframework.web.client.RestTemplate;

@RestController
public class DeptController_Consumer
{
//	private static final String URL_PREFIX = "http://localhost:8001";
	private static final String URL_PREFIX = "http://MICROSERVICECLOUD-DEPT";

	@Autowired
	private RestTemplate restTemplate;

	@PostMapping("/consumer/dept/add")
	public boolean add(@RequestBody Dept dept) {
		return restTemplate.postForObject(URL_PREFIX + "/dept/add", dept, Boolean.class);
	}

	@GetMapping("/consumer/dept/get/{id}")
	public Dept get(@PathVariable("id") Long id) {
		return restTemplate.getForObject(URL_PREFIX + "/dept/get/" + id, Dept.class);
	}

	@GetMapping("/consumer/dept/list")
	public List<Dept> list() {
		return restTemplate.getForObject(URL_PREFIX + "/dept/list", List.class);
	}

	@GetMapping("/consumer/dept/discovery")
	public Object discorery() {
		return restTemplate.getForObject(URL_PREFIX + "/dept/discovery", Object.class);
	}
}
